/**
* Oxide
*
* Copyright (c) 2011 Dinosaur Kick Pty Ltd, All rights reserved.
*
* This source code is made available under the "Modified BSD" licensing arrangement.
* See license.txt for details.
*/
// ----------------------------------------------------------------------------
#include <string>
#include <google/dense_hash_map>
#include "oxide-common/str.hpp"
#include "../token_identity.hpp"
// ----------------------------------------------------------------------------
#ifndef O2_LEX_KEYWORD_MAP_INC
#define O2_LEX_KEYWORD_MAP_INC
namespace o2 {
namespace lex {
// ----------------------------------------------------------------------------

template <typename StringT>
class basic_keyword_map
{
	public:
		typedef StringT string_type;
		typedef google::dense_hash_map<string_type, token_identity> map_type;
		
		basic_keyword_map(void)
		{
			if (s_map.empty())
			{
				s_map.set_empty_key(string_type());
				s_map[O2_STR("abstract")] = TOK_ABSTRACT;
				s_map[O2_STR("class")] = TOK_CLASS;
				s_map[O2_STR("final")] = TOK_FINAL;
				s_map[O2_STR("method")] = TOK_METHOD;
				s_map[O2_STR("private")] = TOK_ACCESS_MODIFIER;
				s_map[O2_STR("protected")] = TOK_ACCESS_MODIFIER;
				s_map[O2_STR("public")] = TOK_ACCESS_MODIFIER;
				s_map[O2_STR("property")] = TOK_PROPERTY;
				s_map[O2_STR("static")] = TOK_STATIC;
				s_map[O2_STR("var")] = TOK_VAR;
			}
		}
		
		token_identity operator[] (const string_type& keyword) const
		{
			typename map_type::const_iterator iter = s_map.find(keyword);
			return iter == s_map.end() ? TOK_IDENTIFIER : iter->second;
		}
	
	private:
		static map_type s_map;
};

template <typename StringT>
typename basic_keyword_map<StringT>::map_type basic_keyword_map<StringT>::s_map;

// ----------------------------------------------------------------------------

typedef basic_keyword_map<std::string> keyword_map;
typedef basic_keyword_map<std::wstring> wkeyword_map;

// ----------------------------------------------------------------------------
} // namespace lex
} // namespace o2
#endif // O2_LEX_KEYWORD_MAP_INC
// ----------------------------------------------------------------------------
